<template>
	<up-popup :show="show" @close="close">
		<view class="page-total">
			<view class="key-box">
				<view class="yuan-box">
					<view v-for="(item, index) in 6">
						<view :class="{'yuan': keyIndex.length >= (index + 1)}"></view>
					</view>
				</view>
				<view class="kuai">
					<view v-for="item in 6"></view>
				</view>
			</view>
			<view class="key-list">
				<view class="list" v-for="(item,index) in keyList"
					@click="onKeyList(item)"
					:key="item.keyCode">
					<text>{{item.key}}</text>
				</view>
			</view>
		</view>
	</up-popup>
</template>

<script setup>
	import { reactive, ref, defineExpose } from 'vue';
	let show = ref(false)

	function close() {
		show.value = false
	}

	const keyList = reactive([{
		key: 1,
		en: '',
		keyCode: 49,
	}, {
		key: 2,
		en: 'ABC',
		keyCode: 50,
	}, {
		key: 3,
		en: 'ABC',
		keyCode: 51,
	}, {
		key: 4,
		en: 'ABC',
		keyCode: 52,
	}, {
		key: 5,
		en: 'ABC',
		keyCode: 53,
	}, {
		key: 6,
		en: 'ABC',
		keyCode: 54,
	}, {
		key: 7,
		en: 'ABC',
		keyCode: 55,
	}, {
		key: 8,
		en: 'ABC',
		keyCode: 56,
	}, {
		key: 9,
		en: 'ABC',
		keyCode: 57,
	}, {
		key: '删除',
		en: 'ABC',
		keyCode: 190,
	}, {
		key: 0,
		en: 'ABC',
		keyCode: 48,
	}, {
		key: '确定',
		en: 'DEL',
		keyCode: 8,
	}])

	const keyIndex = reactive([])
	/**
	 * 密码键盘按下
	 * @param {Object} item
	 */
	function onKeyList(item) {
		if (item.key == '删除') {
			keyIndex.pop();
		} else if (item.key == '确定') {
			emit('submit', keyIndex)
		} else {
			if (keyIndex.length >= 6) return
			keyIndex.push(item.key)
		}
	}

	defineExpose({
		show,
		keyIndex
	})
	const emit = defineEmits(['submit'])
</script>

<style lang="scss">
	.page-total {
		width: 100%;
		background-color: #f6f6f6;
	}

	.key-box {
		display: flex;
		flex-direction: column;
		justify-content: center;
		height: 100rpx;
		padding: 0 80rpx;

		.yuan-box {
			display: flex;
			justify-content: space-between;

			>view {
				display: flex;
				justify-content: center;
				width: 50rpx;
				height: 5rpx;

				.yuan {
					width: 10rpx;
					height: 10rpx;
					border-radius: 10rpx;
					background-color: #000;
				}
			}
		}

		.kuai {
			display: flex;
			justify-content: space-between;
			margin-top: 20rpx;

			>view {
				width: 50rpx;
				height: 5rpx;
				background-color: #000;
			}
		}
	}

	.key-list {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		padding: 1% 3%;
		height: 90%;
		margin-top: 20rpx;

		.list {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 32%;
			height: 92rpx;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
			margin-right: 1.7%;
			margin-bottom: 16rpx;

			text {
				font-size: 38rpx;
				font-weight: bold;
				color: #222222;
			}
		}

		.list:nth-child(3n) {
			margin-right: 0;
		}

		.special {
			background-color: #f6f6f6;
			box-shadow: none;

			text {
				color: #959595;
			}
		}
	}
</style>